<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        ></el-input>
      </el-form-item>
      <el-form-item label="咨询类型" prop="callType">
        <el-select
          v-model="queryParams.callType"
          placeholder="请选择咨询类型"
          clearable
          @change="handleQuery"
        >
          <template v-for="dict in dict.type.calltype">
            <el-option
              v-if="dict.value !== '3'"
               :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </template>
        </el-select>
      </el-form-item>
      <el-form-item label="结算状态" prop="billStatus">
        <el-select
          v-model="queryParams.billStatus"
          placeholder="请选择结算状态"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="dict in dict.type.billstatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择订单状态"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="dict in dict.type.order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单时间">
        <el-date-picker
          v-model="createTime"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          :default-time="['00:00:00', '23:59:59']"
          @change="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="orderList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="咨询订单"
        align="center"
        prop="orderNo"
        min-width="200px"
        fixed="left"
      />
      <el-table-column
        label="订单生成时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="咨询类型"
        align="center"
        prop="callType"
        width="100px"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.calltype" :value="scope.row.callType" />
        </template>
      </el-table-column>
      <el-table-column label="发起终端" align="center" prop="platform" />
      <el-table-column
        label="会议编号"
        align="center"
        prop="meetingRoomNumber"
        width="120px"
      />
      <el-table-column
        label="发起人"
        align="center"
        prop="sponsor"
        width="120px"
      />
      <el-table-column
        label="咨询对象"
        align="center"
        prop="experName"
        show-overflow-tooltip
        min-width="120px"
      />
      <el-table-column
        label="邀请嘉宾"
        align="center"
        prop="inviteGuests"
        show-overflow-tooltip
        min-width="150px"
      />
      <el-table-column
        label="咨询开始时间"
        align="center"
        prop="callTimestart"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.callTimestart) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="咨询结束时间"
        align="center"
        prop="callTimeend"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.callTimeend) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="通话总时长"
        align="center"
        prop="callTimeend"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.talktime || 0 }}分</span>
        </template>
      </el-table-column>

      <el-table-column
        label="应付（原价）"
        align="center"
        prop="costOriginal"
        width="100px"
      >
        <template slot-scope="{ row }">
          <span>￥{{ row.costOriginal || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="应付（实际）"
        align="center"
        prop="cost"
        width="100px"
      >
        <template slot-scope="{ row }">
          <span>￥{{ row.cost || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已结算金额" align="center" width="100">
        <template slot-scope="{ row }">
          <span>￥{{ row.billcost || 0 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="支付人"
        align="center"
        prop="playUser"
        width="100px"
      />
      <el-table-column
        label="支付方式"
        align="center"
        prop="playType"
        width="100px"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.pay_sdktype"
            :value="scope.row.playType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="支付时间"
        align="center"
        prop="playCreateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.playCreateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="订单状态"
        align="center"
        prop="status"
        width="100px"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.order_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="结算状态"
        align="center"
        prop="billStatus"
        width="100px"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.billstatus"
            :value="scope.row.billStatus"
          />
        </template>
      </el-table-column>
      <el-table-column label="退款金额" align="center" prop="refundcost">
        <template slot-scope="{ row }">
          <span>￥{{ row.refundcost || 0 }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column
        label="咨询方式"
        align="center"
        prop="callMethod"
        width="100px"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.call_method"
            :value="scope.row.callMethod"
          />
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        label="咨询标准"
        align="center"
        prop="consultingStandards"
        width="100px"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.consulting_standards"
            :value="scope.row.consultingStandards"
          />
        </template>
      </el-table-column> -->

      <el-table-column label="操作" align="center" width="180px" fixed="right">
        <template slot-scope="scope">
          <div>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-s-order"
              @click="$router.push(`/order/orderDetails/index/${scope.row.id}`)"
              v-hasPermi="['order:order:details']"
            >
              订单详情
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-video-camera"
              v-hasPermi="['order:order:videoList']"
              @click="$router.push(`/order/videoList/index/${scope.row.id}`)"
            >
              录制列表
            </el-button>
          </div>
          <div>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-postcard"
              @click="
                $router.push(`/order/consultdetails/index/${scope.row.orderNo}`)
              "
              v-hasPermi="['order:order:consult']"
            >
              咨询记录
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-postcard"
              @click="
                $router.push(`/order/resultdetails/index/${scope.row.id}`)
              "
              v-hasPermi="['order:order:settlement']"
            >
              结算汇总
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      :title="vodsTitle"
      :visible.sync="vodsOpen"
      width="1000px"
      append-to-body
    >
      <el-table :data="vodsList">
        <el-table-column label="id" align="center" prop="vodId" />
        <el-table-column label="视频名称" align="center" prop="displayName" />
        <el-table-column label="开始时间" align="center" prop="startTime" />
        <el-table-column label="结束时间" align="center" prop="endTime" />
        <el-table-column label="文件大小" align="center" prop="fileSize" />
        <el-table-column label="设备号" align="center" prop="nemoNumber" />
        <el-table-column
          label="下载链接"
          align="center"
          prop="transcriptionTxtFileUrl"
        />
      </el-table>

      <pagination
        v-show="vodsTotal > 0"
        :total="vodsTotal"
        :page.sync="vodsQueryParams.pageNum"
        :limit.sync="vodsQueryParams.pageSize"
        @pagination="getVodsList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="vodsCancel">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改会议对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :show-message="false" label-width="80px">
        <el-form-item label="云会议号" prop="meetingRoomNumber">
          <el-input
            v-model="form.meetingRoomNumber"
            placeholder="请输入云会议号"
          />
        </el-form-item>
        <el-form-item label="房间号" prop="meetingId">
          <el-input v-model="form.meetingId" placeholder="请输入房间号" />
        </el-form-item>
        <el-form-item label="客户端id" prop="clientId">
          <el-input v-model="form.clientId" placeholder="请输入客户端id" />
        </el-form-item>
        <el-form-item label="房间标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入房间标题" />
        </el-form-item>
        <el-form-item label="顾客名字" prop="username">
          <el-input v-model="form.username" placeholder="请输入顾客名字" />
        </el-form-item>
        <el-form-item label="顾客手机号" prop="userphone">
          <el-input v-model="form.userphone" placeholder="请输入顾客手机号" />
        </el-form-item>
        <el-form-item label="专家编号" prop="expertId">
          <el-input v-model="form.expertId" placeholder="请输入专家编号" />
        </el-form-item>
        <el-form-item label="专家名称" prop="experName">
          <el-input v-model="form.experName" placeholder="请输入专家名称" />
        </el-form-item>
        <el-form-item label="通话开始时间" prop="callTimestart">
          <el-date-picker
            clearable
            v-model="form.callTimestart"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择通话开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="通话结束时间" prop="callTimeend">
          <el-date-picker
            clearable
            v-model="form.callTimeend"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择通话结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总费用(实际)" prop="cost">
          <el-input v-model="form.cost" placeholder="请输入总费用(实际)" />
        </el-form-item>
        <el-form-item label="用户费用" prop="costUser">
          <el-input v-model="form.costUser" placeholder="请输入用户费用" />
        </el-form-item>
        <el-form-item label="专家发起人费用" prop="costExp">
          <el-input v-model="form.costExp" placeholder="请输入专家发起人费用" />
        </el-form-item>
        <el-form-item label="其他专家费用" prop="costToexp">
          <el-input v-model="form.costToexp" placeholder="请输入其他专家费用" />
        </el-form-item>
        <el-form-item label="渠道费用" prop="costChannel">
          <el-input v-model="form.costChannel" placeholder="请输入渠道费用" />
        </el-form-item>
        <el-form-item label="平台费用" prop="costPlatform">
          <el-input v-model="form.costPlatform" placeholder="请输入平台费用" />
        </el-form-item>
        <el-form-item label="邀请码" prop="invitation">
          <el-input v-model="form.invitation" placeholder="请输入邀请码" />
        </el-form-item>
        <el-form-item label="咨询方式" prop="callMethod">
          <el-input v-model="form.callMethod" placeholder="请输入咨询方式" />
        </el-form-item>
        <el-form-item label="邀请嘉宾" prop="inviteGuests">
          <el-input v-model="form.inviteGuests" placeholder="请输入邀请嘉宾" />
        </el-form-item>
        <!-- <el-form-item label="咨询标准" prop="consultingStandards">
          <el-input
            v-model="form.consultingStandards"
            placeholder="请输入咨询标准"
          />
        </el-form-item> -->
        <el-form-item label="总费用(原价)" prop="costOriginal">
          <el-input
            v-model="form.costOriginal"
            placeholder="请输入总费用(原价)"
          />
        </el-form-item>
        <el-form-item label="发起单位费用" prop="costCom">
          <el-input v-model="form.costCom" placeholder="请输入发起单位费用" />
        </el-form-item>
        <el-form-item label="咨询渠道费用" prop="costTochannel">
          <el-input
            v-model="form.costTochannel"
            placeholder="请输入咨询渠道费用"
          />
        </el-form-item>
        <el-form-item label="咨询单位费用" prop="costTocom">
          <el-input v-model="form.costTocom" placeholder="请输入咨询单位费用" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  addOrder,
  updateOrder,
  vods,
} from "@/api/order/order";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { getPickerShortcuts } from '@/utils'

export default {
  name: "Order",
  dicts: [
    "calltype",
    "call_method",
    "order_status",
    "consulting_standards",
    "billstatus",
    "pay_sdktype",
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      vodsTotal: 0,
      // 会议表格数据
      orderList: [],
      vodsList: [],
      // 弹出层标题
      title: "",
      vodsTitle: "视频列表",
      // 是否显示弹出层
      open: false,
      vodsOpen: false,
      // 查询参数
      pickerOptions: {
        shortcuts: getPickerShortcuts()
      },
      createTime: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        callType: null,
        callMethod: null,
        consultingStandards: null,
        billStatus: null,
        status: null,
        createTimegt: "", // 开始时间
        createTimelt: "", // 结束时间
      },
      vodsQueryParams: {
        pageNum: 0,
        pageSize: 10,
        meetingRoomNumber: null,
        meetingId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    /** 查询会议列表 */
    getList() {
      this.loading = true;
      this.queryParams.createTimegt = this.createTime && this.createTime.length ? this.createTime[0] : "";
      this.queryParams.createTimelt = this.createTime && this.createTime.length ? this.createTime[1] : "";
      listOrder(this.queryParams).then((response) => {
        this.orderList = response.data.list;
        this.total = response.data.total;
      }).finally(()=>{
        this.loading = false;
      })
    },
    /** 查询会议列表 */
    getVodsList() {
      vods(this.vodsQueryParams).then((response) => {
        this.vodsList = response.data.list;
        this.vodsTotal = response.data.rowsTotal;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    vodsCancel() {
      this.vodsOpen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        meetingRoomNumber: null,
        meetingId: null,
        clientId: null,
        title: null,
        username: null,
        userphone: null,
        expertId: null,
        experName: null,
        callTimestart: null,
        callTimeend: null,
        cost: null,
        costUser: null,
        costExp: null,
        costToexp: null,
        costChannel: null,
        costPlatform: null,
        status: "0",
        invitation: null,
        callType: null,
        callMethod: null,
        inviteGuests: null,
        consultingStandards: null,
        costOriginal: null,
        costCom: null,
        costTochannel: null,
        costTocom: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会议";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getOrder(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会议";
      });
    },
    /** 修改按钮操作 */
    handleUpdateVods(row) {
      this.vodsOpen = true;
      this.vodsQueryParams.meetingRoomNumber = row.meetingRoomNumber;
      this.vodsQueryParams.meetingId = row.meetingId;
      this.getVodsList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除会议编号为"' + ids + '"的数据项？')
        .then(function () {
          return delOrder(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    }
  },
};
</script>
